package com.gsafety.library.Net.okhttputil.interceptor;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public abstract class URLReplaceInterceptor implements Interceptor
{
    @Override
    public Response intercept(Chain chain) throws IOException
    {
        Request oldRequest = chain.request();
        String oldUrl = oldRequest.url().url().toString();
        String newUrl = urlReplace(oldUrl);
        Request newRequest = oldRequest.newBuilder().url(newUrl).build();
        return chain.proceed(newRequest);
    }
    protected abstract String urlReplace(String oldUrl);
}
